package com.caregiver.watch.business.user.enums;

import lombok.Getter;

import java.time.LocalDate;
import java.time.LocalDateTime;


/**
 * 星期枚举类
 */
@Getter
public enum WeekDayEnum {
    
    MONDAY(1, "周一"),
    TUESDAY(2, "周二"),
    WEDNESDAY(3, "周三"),
    THURSDAY(4, "周四"),
    FRIDAY(5, "周五"),
    SATURDAY(6, "周六"),
    SUNDAY(7, "周日");

    private final int value;
    private final String description;

    WeekDayEnum(int value, String description) {
        this.value = value;
        this.description = description;
    }

    /**
     * 根据值获取星期枚举
     *
     * @param localDate 时间
     * @return 对应的星期枚举
     */
    public static WeekDayEnum parse(LocalDate localDate) {
        // 获取星期值
        int value = localDate.getDayOfWeek().getValue();
        for (WeekDayEnum day : WeekDayEnum.values()) {
            if (day.value == value) {
                return day;
            }
        }
        throw new IllegalArgumentException("无效的星期值: " + value);
    }

    /**
     * 根据值获取星期枚举
     *
     * @param localDateTime 时间
     * @return 对应的星期枚举
     */
    public static WeekDayEnum parse(LocalDateTime localDateTime) {
        // 获取星期值
        int value = localDateTime.getDayOfWeek().getValue();
        for (WeekDayEnum day : WeekDayEnum.values()) {
            if (day.value == value) {
                return day;
            }
        }
        throw new IllegalArgumentException("无效的星期值: " + value);
    }
}
